package servlets.ads;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class StartPayPalPayment extends HttpServlet {
	
	private static final long serialVersionUID = -3063358569058073504L;
	private static final String PAYPALURLBASE = "http://localhost:8080/PayPalRESTWebService/StartPayment";

	protected void doGet(HttpServletRequest request, HttpServletResponse response){
		String emailOwner, cost, idUser, idAdvertisement, returnUrl;
		emailOwner = request.getParameter("emailOwner");
		cost = request.getParameter("cost");
		idUser = request.getParameter("idUser");
		idAdvertisement = request.getParameter("idAdvertisement");
		returnUrl = request.getParameter("returnUrl");
		String url = PAYPALURLBASE + "?emailOwner="+ emailOwner + "&cost="+ cost + "&idUser="+ idUser + "&idAdvertisement="+ idAdvertisement + "&returnUrl="+ returnUrl;
		String cleanUrl = url.replace(" ", "%20");
		
		try {
			response.sendRedirect(cleanUrl);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
